﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace CSVExportImport.Columns.Templates
{
    public class StringColumnTemplate : IColumnTemplate
    {
        private string propertyName;
        public StringColumnTemplate(String propertyName, String header)
        {
            Header = header;
            this.propertyName = propertyName;
        }

        public string Header
        {
            get;
            set;
        }

        private PropertyInfo info = null;
        public PropertyInfo GetPropertyInfo(object obj)
        {
            if (info == null)
            {
                info = obj.GetType().GetProperty(propertyName);
            }
            return info;
        }

        public string GetValue(object obj)
        {
            return (String)GetPropertyInfo(obj).GetValue(obj, null);
        }

        public void SetValue(object obj, string value)
        {
            GetPropertyInfo(obj).SetValue(obj, value, null);
        }
    }
}
